<template>
  <div class="public_main">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>{{$t('newcrumbs.crumbsEle')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('newcrumbs.crumbsTwo')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('riskManage.crumbsTwo')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    
    <!-- -------------搜索查询栏------------------------ -->
    <search :searchData="searchData" 
        @search="search"  
        :searchRight="true"
        :outputRight="false">
    </search>

    <div class="list_operation" v-if="$store.state.common.permiss.artificialtriallist.includes('transfer')">
      <el-button type="primary" @click="todayRedeploy">{{$t('new.no1')}}</el-button>
    </div>

    <!-- -------------表单显示栏------------------------ -->
    <div class="table">
      <template>
        <el-table :data="tableData" stripe size="small"  v-loading="loadFlag" @selection-change="handleSelectionChange">
          <el-table-column type="selection" :selectable="unSelect" width="55">
          </el-table-column>
          <el-table-column align="center" prop="id" :label="$t('public.orderId')" >
          </el-table-column>
          <el-table-column align="center" prop="userId" :label="$t('public.userId')">
          </el-table-column>
          <el-table-column align="center" prop="userName" :label="$t('public.name')">
          </el-table-column>
          <el-table-column align="center" prop="userPhone" :label="$t('public.userTel')">
          </el-table-column>
          <el-table-column align="center" prop="loanAmount" :label="$t('public.no30')">
            <template slot-scope="scope">
              <span v-if="scope.row.loanAmount!==null&&scope.row.loanAmount!==undefined&&scope.row.loanAmount!==''">{{$store.state.common.id_currency}}{{$store.getters.moneySplit(scope.row.loanAmount)}}{{$store.state.common.vi_currency}}</span>
              <span v-else>{{$store.state.common.nullData}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="productPeriod" :label="$t('public.no31')+'('+$t('public.no26')+')'">
          </el-table-column>
          <el-table-column align="center" prop="createTime" :label="$t('public.CreateDate')" width="86">
          </el-table-column>
          <el-table-column align="center" prop="orderExtra.firstApproveTime" :label="$t('new.no9')" width="86">
          </el-table-column>
          <el-table-column align="center" prop="status" :label="$t('public.orderStatus')">
            <template slot-scope="scope">
              <span>{{$t($store.getters.rejectStatus(scope.row.status))}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="orderExtra.approveName" :label="$t('public.no32')">
          </el-table-column>
          <el-table-column align="center" prop="orderExtra.appName" :label="$t('public.appName')">
          </el-table-column>
            <el-table-column align="center" prop="orderExtra.appPackage" :label="$t('public.appPackage')">
          </el-table-column>
          <el-table-column fixed="right" align="center" prop="operation" :label="$t('public.operation')" min-width="160">
            <template slot-scope="scope">
              <span 
                v-if="$store.state.common.permiss.artificialtriallist.includes('view')"
                class="table_opr"
                @click="detail(scope.row.userId,scope.row.id)">
                {{$t('public.detail')}}
              </span>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>

    <!-- ------------  分页显示栏  ------------------------ -->
    <el-row type="flex" justify="end">
      <div class="pages" >
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          layout="sizes, prev, pager, next, total,->"
          :page-sizes="pagination.pageSizeOptions"
          :page-size="pagination.pageSize"
          @size-change="handleSizeChange"
          :total="pagination.total">
        </el-pagination>
      </div>
    </el-row>

    <!-- ------------------ 点击转派弹窗开始 -------------------- -->
    <el-dialog :title="$t('new.no1')" :visible.sync="redeployFlag" width="650px">
      <div class="left2right">
        <span class="left">{{$t('public.orderId')}}:</span>
        <span class="right">{{orderIds.join()}}</span>
      </div>
      <div class="left2right">
        <span class="left">{{$t('public.userId')}}:</span>
        <span class="right">{{userIds.join()}}</span>
      </div>
      <div class="left2right">
        <span class="left">{{$t('loanAfterManage.redeployTo')}}:</span>
        <div class="right">
          <el-select size="small" v-model="redeployStatus" :placeholder="$t('public.placeholder')">
            <el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="left2right">
        <span class="left">{{$t('loanAfterManage.reason')}}:</span>
        <div class="right">
          <el-input type="textarea" :rows="4" v-model="reason" maxlength="600"></el-input>
        </div>
      </div>
      <div class="left2right">
        <span class="left"></span>
        <div class="right">
          <el-button type="primary" size="small" @click="redeploySubmit">{{$t('new.no14')}}</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- ------------------ 点击转派弹窗结束 -------------------- -->

    <div class="foot"></div>

  </div>
</template>
<script>
import getApp from 'src/mixins/getApp.js';//获取app和aok
import getGroupMem from 'src/mixins/getGroupMem.js';//获取审核人员下拉
export default {
  name: 'peopleFirstAudit',
  mixins:[getApp,getGroupMem],
  data () {
      const searchData=[
      {
        type: 'input',
        label: 'public.orderId',
        attr: 'orderId',
        value: ''
      },
      {
        type: 'input',
        label: 'public.userId',
        attr: 'userId',
        value: ''
      },
      {
        type: 'input',
        label: 'public.name',
        attr: 'userName',
        value: ''
      },
      {
        type: 'input',
        label: 'public.userPhone',
        attr: 'userPhone',
        value: ''
      },{
        type: 'select',
        attr: 'adminId',
        label: 'public.no32',
        option: [], // 订单状态下拉选框信息
        value: '',
        langFlag: false,
      },{
        type: 'select',
        attr: 'status',
        label: 'public.orderStatus',
        option: this.$store.state.options.order_select, // 订单状态下拉选框信息
        value: '',
        langFlag: true,
      },{
        type: 'rangePicker',
        label: 'public.CreateDate',
        attr: 'searchTime1',
        value: [],
      },{
        type: 'rangePicker',
        label: 'new.no9',
        attr: 'searchTime2',
        value: [],
      },{
        type: 'select',
        attr: 'appName',
        label: 'public.appName',
        option: [],
        value: '',
        langFlag: false,
      },{
        type: 'select',
        attr: 'appPackage',
        label: 'public.appPackage',
        option: [],
        value: '',
        langFlag: false,
      }
    ]
    return {
      flag: true,
      loadFlag: true,
      pagination: {
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      searchData:searchData,
      formInline: {// 用户查询信息数据对应字段
        orderId: '',
        userId: '',
        userName: '',
        userPhone: '',
        adminId: '',
        status: '',
        applyTimeBegin:'',
        applyTimeEnd:'',
        approveTimeBegin:'',
        approveTimeEnd:'',
        appName:'',
        appPackage:''
      },
      options1: [], // 审核员下拉选框信息
      options2: this.$store.state.options.peopleAuditOneStatus_options1, // 订单状态下拉选框信息
      options4: this.$store.state.options.loansType_options, // 贷款类型下拉选框信息
      tableData: [], // 用户信息数据模拟
      multipleSelection: [],
      redeployFlag: false, // 转派弹窗开关
      redeployStatus: '', // 选中的信审员
      reason: '', // 备注
      orderIds: [], // 选中订单id集合
      userIds: [], // 选中的用户ID集合
    }
  },
  methods: {
    handleSizeChange (val) {// 每页条数变化时操作
      this.pagination.pageSize = val;
      this.getTableData();
    },
    handleCurrentChange (val) { // 分页按钮点击操作
      this.pagination.current = val;
      this.getTableData();
    },
    search(search) { // 搜索
        this.formInline=search;
        this.formInline.applyTimeBegin=search.searchTime1?search.searchTime1[0]:'';
        this.formInline.applyTimeEnd=search.searchTime1?search.searchTime1[1]:'';
        this.formInline.approveTimeBegin=search.searchTime2?search.searchTime2[0]:'';
        this.formInline.createTapproveTimeEndimeEnd=search.searchTime2?search.searchTime2[1]:'';
        if (this.flag) {
          this.flag = false;
          this.pagination.current = 1;
          this.getTableData();
        }
    },
    detail (userId, orderId) { // 点击查看详情
        this.$router.push({path: '/artificialdetail', query: {userId, orderId,'from':'triallist'}});   
    },
    getTableData () { // 获取初审列表数据
      this.loadFlag = true;
      let option = {
        pageNum:this.pagination.current,
        pageSize:this.pagination.pageSize,
        param: {
          ...this.formInline
        }       
      }
      this.$axios.post(this.$action.risk_approveFirstList, option).then(res => {
        this.flag = true;
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.pagination.total = res.data.total;
        }else{
          this.$globalMsg.error(res.data.message)
        }
        this.loadFlag = false;
      })
    },
    handleSelectionChange (val) { // 表格选中项数据
      this.multipleSelection = val;
    },
    unSelect (row) {
      return row.status == 10;
    },
    todayRedeploy () { // 转派按钮点击操作
      if (this.orderIds == '') {
        this.$globalMsg.error(this.$t('loanAfterManage.selFirst'));
      } else {
        this.redeployFlag = true;
      }
    },
    redeployClose () {
      this.redeployFlag = false;
      this.redeployStatus = '';
      this.reason = '';
    },
    joinType () { // 订单转派弹窗对应数据处理
      let arr = [];
      let brr = [];
      this.multipleSelection.forEach(value => {
        arr.push(value.id);
        brr.push(value.userId);
      })
      this.orderIds = arr;
      this.userIds = brr;
    },
    redeploySubmit () { // 转派确认操作
      if (this.redeployStatus == '') {
        this.$globalMsg.error(this.$t('loanAfterManage.adminFirst'));
        return;
      }
      if (this.reason == '') {
        this.$globalMsg.error(this.$t('loanAfterManage.placeholder'));
        return;
      }
      if (this.flag) {
        this.flag = false;
        let option = {
          param:{
            ids: this.orderIds,
            supervisorId:sessionStorage.sessionid,
            approveType: '2',
            remark: this.reason,
            adminId: this.redeployStatus
          }
        }
        this.$axios.post(this.$action.risk_approveAppoint, option).then(res => {
          this.flag = true;
          if (res.code == 200) {
            this.$globalMsg.success(this.$t('message.success'));
          } else {
            this.$globalMsg.error(res.message);
          }
          this.getTableData();
          this.redeployStatus = '';
          this.reason = '';
          this.redeployFlag = false;
        })
      }
    }
  },
  watch: {
    multipleSelection () {
      this.joinType();
    }
  },
  mounted () {
    this.getApp().then(app=>{
      this.searchData[8].option=app.appName;
      this.searchData[9].option=app.appPackage;
    })
    this.getGroupMem(2).then(arr=>{
      this.searchData[4].option=arr;
      this.options1=arr;
    })
    this.getTableData();// 获取初审列表数据
  }
}
</script>
<style scoped lang="scss">

</style>
